#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

struct ele{
    int hang,lie,data;
}*g;

bool cpr(ele a, ele b){
    if(a.hang==b.hang)return a.lie<b.lie;
    return a.hang<b.hang;
}

int main(){
    int n,gg;
    cin>>n>>gg;
    g = new ele [gg];
    for(int i=0;i<gg;i++)cin>>g[i].hang>>g[i].lie>>g[i].data;
    int temp;
    for(int i=0;i<gg;i++){
        temp=g[i].hang;
        g[i].hang=g[i].lie;
        g[i].lie=temp;
    }
    sort(g,g+gg,cpr);
    for(int i=0;i<gg;i++){
        cout<<g[i].hang<<" "<<g[i].lie<<" "<<g[i].data<<endl;
    }
}
